<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title >日期和数学练习</title>
</head>
<body>

</body>
<script>
    /**
     *  1. YYYY-MM-dd hh:mm:ss
     * */

    function printDate() {

        var d1 = new Date();

        var myDate = {
            year: d1.getFullYear(),
            month: (d1.getMonth() + 1),
            date2: d1.getDate(),
            hour: d1.getHours(),
            min: d1.getMinutes(),
            second: d1.getSeconds()
        }
        /**
         *  1.未完成的需求
         *     1) 如果数字是1位，应显示成‘0x'
         *     2) 日期和时间之间 需要添加间隙
         * */
        var resDate = myDate.year.toString()
            .concat('-')
            .concat(myDate.month>10?myDate.month:'0'+myDate.month)
            .concat('-')
            .concat(myDate.date2>10?myDate.date2:'0'+myDate.date2)
            .concat('&nbsp')
            .concat('&nbsp')
            .concat(myDate.hour)
            .concat(':')
            .concat(myDate.min)
            .concat(':')
            .concat(myDate.second>10?myDate.second:'0'+myDate.second);

        document.writeln(resDate);

    }

    printDate();



</script>
</html>